<?php
function controller_bimbel($config) {
    $db = new db($config);
	//slider
    $uploaddir = $config['image_path'].'bimbel'.DIRECTORY_SEPARATOR;
	$limitedext = array("jpg","jpeg","png","bmp");
	$cfiles = 0;
	$gambar = array();
	$files = scandir($uploaddir.'slide'.DIRECTORY_SEPARATOR);
	for($i = 0; $i < count($files); $i++) {
		$file = $files[$i];
		$getExt = explode('.',$file);
		$file_ext = $getExt[count($getExt)-1];
		if (in_array($file_ext,$limitedext)) {
			$img = $config['image_url'].'bimbel/slide/'.$file;
			array_push($gambar, $img);
		}
	}
	$param['slide'] = $gambar;
	//deskripsi
	$result = $db->query( "SELECT * FROM `deskripsi` WHERE page = 'bimbel'" );
	$desc = str_replace("\n", "<br />", $result[0]['deskripsi']);
	$param['deskripsi'] = $desc;
	//twitter
	$result = $db->query( "SELECT twitter FROM `footer` WHERE 1" );
	$param['twitter'] = $result[0]['twitter'];
	//kontak
	$result = $db->query("SELECT * FROM `kontak` WHERE page='bimbel'");
	$param['kontak'] = $result[0];
	//kegiatan
	$result = $db->query("SELECT * FROM `bimbel` WHERE 1");
	$param['kegiatan'] = array();
	foreach ($result as $kegiatan){
		//sanggar
		$id = $kegiatan['idBimbel'];
		$param['kegiatan'][$id] = $kegiatan;
		//slider
		$uploaddir = $config['image_path'].'bimbel'.DIRECTORY_SEPARATOR.'foto'.DIRECTORY_SEPARATOR;
		$gambar = array();
		$regex = $uploaddir.$id."-*";
		$limitedext = array("jpg","jpeg","png","bmp");
		//slide
		foreach (glob($regex) as $files) {
			$getFile = explode(DIRECTORY_SEPARATOR,$files);
			$file = $getFile[count($getFile)-1];
			$getExt = explode('.',$file);
			$file_ext = $getExt[count($getExt)-1];
			if (in_array($file_ext,$limitedext)) {
				$img = $config['image_url'].'bimbel/foto/'.$file;
				array_push($gambar, $img);
			}
		}
		$param['kegiatan'][$id]['slide'] = $gambar;
	}
	//$param['kegiatan'] = $result;
	//
	view_bimbel($config, $param);
}
